package com.itheima.service.impl;

import com.itheima.dao.AccountDao;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * 包名:com.itheima.service.impl
 * 作者:Leevi
 * 日期2020-02-21  10:07
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    @Override
    @Transactional
    public void transfer(Map paramMap) {
        Map map = new HashMap();
        map.put("id",paramMap.get("fromId"));
        map.put("money",-Double.parseDouble((String) paramMap.get("money")));
        //1. 付款方扣款
        accountDao.update(map);

        //int num = 10/0;

        //2. 收款方收款
        map.put("id",paramMap.get("toId"));
        map.put("money",Double.parseDouble((String) paramMap.get("money")));

        accountDao.update(map);
    }
}
